module canvas.keys;

import canvas.keysyms;
import derelict.sdl.sdl;

struct SDLToKeycode {
    int sdlcode;
    Keycode code;
}

SDLToKeycode g_sdl_to_code[] = [
    {SDLK_BACKSPACE, Keycode.BACKSPACE},
    {SDLK_TAB, Keycode.TAB},
    {SDLK_CLEAR, Keycode.CLEAR},
    {SDLK_RETURN, Keycode.RETURN},
    {SDLK_PAUSE, Keycode.PAUSE},
    {SDLK_ESCAPE, Keycode.ESCAPE},
    {SDLK_SPACE, Keycode.SPACE},
    {SDLK_EXCLAIM, Keycode.EXCLAIM},
    {SDLK_QUOTEDBL, Keycode.QUOTEDBL},
    {SDLK_HASH, Keycode.HASH},
    {SDLK_DOLLAR, Keycode.DOLLAR},
    {SDLK_AMPERSAND, Keycode.AMPERSAND},
    {SDLK_QUOTE, Keycode.QUOTE},
    {SDLK_LEFTPAREN, Keycode.LEFTPAREN},
    {SDLK_RIGHTPAREN, Keycode.RIGHTPAREN},
    {SDLK_ASTERISK, Keycode.ASTERISK},
    {SDLK_PLUS, Keycode.PLUS},
    {SDLK_COMMA, Keycode.COMMA},
    {SDLK_MINUS, Keycode.MINUS},
    {SDLK_PERIOD, Keycode.PERIOD},
    {SDLK_SLASH, Keycode.SLASH},
    {SDLK_0, Keycode.N0},
    {SDLK_1, Keycode.N1},
    {SDLK_2, Keycode.N2},
    {SDLK_3, Keycode.N3},
    {SDLK_4, Keycode.N4},
    {SDLK_5, Keycode.N5},
    {SDLK_6, Keycode.N6},
    {SDLK_7, Keycode.N7},
    {SDLK_8, Keycode.N8},
    {SDLK_9, Keycode.N9},
    {SDLK_COLON, Keycode.COLON},
    {SDLK_SEMICOLON, Keycode.SEMICOLON},
    {SDLK_LESS, Keycode.LESS},
    {SDLK_EQUALS, Keycode.EQUALS},
    {SDLK_GREATER, Keycode.GREATER},
    {SDLK_QUESTION, Keycode.QUESTION},
    {SDLK_AT, Keycode.AT},
    {SDLK_LEFTBRACKET, Keycode.LEFTBRACKET},
    {SDLK_BACKSLASH, Keycode.BACKSLASH},
    {SDLK_RIGHTBRACKET, Keycode.RIGHTBRACKET},
    {SDLK_CARET, Keycode.CARET},
    {SDLK_UNDERSCORE, Keycode.UNDERSCORE},
    {SDLK_BACKQUOTE, Keycode.BACKQUOTE},
    {SDLK_a, Keycode.A},
    {SDLK_b, Keycode.B},
    {SDLK_c, Keycode.C},
    {SDLK_d, Keycode.D},
    {SDLK_e, Keycode.E},
    {SDLK_f, Keycode.F},
    {SDLK_g, Keycode.G},
    {SDLK_h, Keycode.H},
    {SDLK_i, Keycode.I},
    {SDLK_j, Keycode.J},
    {SDLK_k, Keycode.K},
    {SDLK_l, Keycode.L},
    {SDLK_m, Keycode.M},
    {SDLK_n, Keycode.N},
    {SDLK_o, Keycode.O},
    {SDLK_p, Keycode.P},
    {SDLK_q, Keycode.Q},
    {SDLK_r, Keycode.R},
    {SDLK_s, Keycode.S},
    {SDLK_t, Keycode.T},
    {SDLK_u, Keycode.U},
    {SDLK_v, Keycode.V},
    {SDLK_w, Keycode.W},
    {SDLK_x, Keycode.X},
    {SDLK_y, Keycode.Y},
    {SDLK_z, Keycode.Z},
    {SDLK_DELETE, Keycode.DELETE},
    {SDLK_WORLD_0, Keycode.WORLD_0},
    {SDLK_WORLD_1, Keycode.WORLD_1},
    {SDLK_WORLD_2, Keycode.WORLD_2},
    {SDLK_WORLD_3, Keycode.WORLD_3},
    {SDLK_WORLD_4, Keycode.WORLD_4},
    {SDLK_WORLD_5, Keycode.WORLD_5},
    {SDLK_WORLD_6, Keycode.WORLD_6},
    {SDLK_WORLD_7, Keycode.WORLD_7},
    {SDLK_WORLD_8, Keycode.WORLD_8},
    {SDLK_WORLD_9, Keycode.WORLD_9},
    {SDLK_WORLD_10, Keycode.WORLD_10},
    {SDLK_WORLD_11, Keycode.WORLD_11},
    {SDLK_WORLD_12, Keycode.WORLD_12},
    {SDLK_WORLD_13, Keycode.WORLD_13},
    {SDLK_WORLD_14, Keycode.WORLD_14},
    {SDLK_WORLD_15, Keycode.WORLD_15},
    {SDLK_WORLD_16, Keycode.WORLD_16},
    {SDLK_WORLD_17, Keycode.WORLD_17},
    {SDLK_WORLD_18, Keycode.WORLD_18},
    {SDLK_WORLD_19, Keycode.WORLD_19},
    {SDLK_WORLD_20, Keycode.WORLD_20},
    {SDLK_WORLD_21, Keycode.WORLD_21},
    {SDLK_WORLD_22, Keycode.WORLD_22},
    {SDLK_WORLD_23, Keycode.WORLD_23},
    {SDLK_WORLD_24, Keycode.WORLD_24},
    {SDLK_WORLD_25, Keycode.WORLD_25},
    {SDLK_WORLD_26, Keycode.WORLD_26},
    {SDLK_WORLD_27, Keycode.WORLD_27},
    {SDLK_WORLD_28, Keycode.WORLD_28},
    {SDLK_WORLD_29, Keycode.WORLD_29},
    {SDLK_WORLD_30, Keycode.WORLD_30},
    {SDLK_WORLD_31, Keycode.WORLD_31},
    {SDLK_WORLD_32, Keycode.WORLD_32},
    {SDLK_WORLD_33, Keycode.WORLD_33},
    {SDLK_WORLD_34, Keycode.WORLD_34},
    {SDLK_WORLD_35, Keycode.WORLD_35},
    {SDLK_WORLD_36, Keycode.WORLD_36},
    {SDLK_WORLD_37, Keycode.WORLD_37},
    {SDLK_WORLD_38, Keycode.WORLD_38},
    {SDLK_WORLD_39, Keycode.WORLD_39},
    {SDLK_WORLD_40, Keycode.WORLD_40},
    {SDLK_WORLD_41, Keycode.WORLD_41},
    {SDLK_WORLD_42, Keycode.WORLD_42},
    {SDLK_WORLD_43, Keycode.WORLD_43},
    {SDLK_WORLD_44, Keycode.WORLD_44},
    {SDLK_WORLD_45, Keycode.WORLD_45},
    {SDLK_WORLD_46, Keycode.WORLD_46},
    {SDLK_WORLD_47, Keycode.WORLD_47},
    {SDLK_WORLD_48, Keycode.WORLD_48},
    {SDLK_WORLD_49, Keycode.WORLD_49},
    {SDLK_WORLD_50, Keycode.WORLD_50},
    {SDLK_WORLD_51, Keycode.WORLD_51},
    {SDLK_WORLD_52, Keycode.WORLD_52},
    {SDLK_WORLD_53, Keycode.WORLD_53},
    {SDLK_WORLD_54, Keycode.WORLD_54},
    {SDLK_WORLD_55, Keycode.WORLD_55},
    {SDLK_WORLD_56, Keycode.WORLD_56},
    {SDLK_WORLD_57, Keycode.WORLD_57},
    {SDLK_WORLD_58, Keycode.WORLD_58},
    {SDLK_WORLD_59, Keycode.WORLD_59},
    {SDLK_WORLD_60, Keycode.WORLD_60},
    {SDLK_WORLD_61, Keycode.WORLD_61},
    {SDLK_WORLD_62, Keycode.WORLD_62},
    {SDLK_WORLD_63, Keycode.WORLD_63},
    {SDLK_WORLD_64, Keycode.WORLD_64},
    {SDLK_WORLD_65, Keycode.WORLD_65},
    {SDLK_WORLD_66, Keycode.WORLD_66},
    {SDLK_WORLD_67, Keycode.WORLD_67},
    {SDLK_WORLD_68, Keycode.WORLD_68},
    {SDLK_WORLD_69, Keycode.WORLD_69},
    {SDLK_WORLD_70, Keycode.WORLD_70},
    {SDLK_WORLD_71, Keycode.WORLD_71},
    {SDLK_WORLD_72, Keycode.WORLD_72},
    {SDLK_WORLD_73, Keycode.WORLD_73},
    {SDLK_WORLD_74, Keycode.WORLD_74},
    {SDLK_WORLD_75, Keycode.WORLD_75},
    {SDLK_WORLD_76, Keycode.WORLD_76},
    {SDLK_WORLD_77, Keycode.WORLD_77},
    {SDLK_WORLD_78, Keycode.WORLD_78},
    {SDLK_WORLD_79, Keycode.WORLD_79},
    {SDLK_WORLD_80, Keycode.WORLD_80},
    {SDLK_WORLD_81, Keycode.WORLD_81},
    {SDLK_WORLD_82, Keycode.WORLD_82},
    {SDLK_WORLD_83, Keycode.WORLD_83},
    {SDLK_WORLD_84, Keycode.WORLD_84},
    {SDLK_WORLD_85, Keycode.WORLD_85},
    {SDLK_WORLD_86, Keycode.WORLD_86},
    {SDLK_WORLD_87, Keycode.WORLD_87},
    {SDLK_WORLD_88, Keycode.WORLD_88},
    {SDLK_WORLD_89, Keycode.WORLD_89},
    {SDLK_WORLD_90, Keycode.WORLD_90},
    {SDLK_WORLD_91, Keycode.WORLD_91},
    {SDLK_WORLD_92, Keycode.WORLD_92},
    {SDLK_WORLD_93, Keycode.WORLD_93},
    {SDLK_WORLD_94, Keycode.WORLD_94},
    {SDLK_WORLD_95, Keycode.WORLD_95},
    {SDLK_KP0, Keycode.KP0},
    {SDLK_KP1, Keycode.KP1},
    {SDLK_KP2, Keycode.KP2},
    {SDLK_KP3, Keycode.KP3},
    {SDLK_KP4, Keycode.KP4},
    {SDLK_KP5, Keycode.KP5},
    {SDLK_KP6, Keycode.KP6},
    {SDLK_KP7, Keycode.KP7},
    {SDLK_KP8, Keycode.KP8},
    {SDLK_KP9, Keycode.KP9},
    {SDLK_KP_PERIOD, Keycode.KP_PERIOD},
    {SDLK_KP_DIVIDE, Keycode.KP_DIVIDE},
    {SDLK_KP_MULTIPLY, Keycode.KP_MULTIPLY},
    {SDLK_KP_MINUS, Keycode.KP_MINUS},
    {SDLK_KP_PLUS, Keycode.KP_PLUS},
    {SDLK_KP_ENTER, Keycode.KP_ENTER},
    {SDLK_KP_EQUALS, Keycode.KP_EQUALS},
    {SDLK_UP, Keycode.UP},
    {SDLK_DOWN, Keycode.DOWN},
    {SDLK_RIGHT, Keycode.RIGHT},
    {SDLK_LEFT, Keycode.LEFT},
    {SDLK_INSERT, Keycode.INSERT},
    {SDLK_HOME, Keycode.HOME},
    {SDLK_END, Keycode.END},
    {SDLK_PAGEUP, Keycode.PAGEUP},
    {SDLK_PAGEDOWN, Keycode.PAGEDOWN},
    {SDLK_F1, Keycode.F1},
    {SDLK_F2, Keycode.F2},
    {SDLK_F3, Keycode.F3},
    {SDLK_F4, Keycode.F4},
    {SDLK_F5, Keycode.F5},
    {SDLK_F6, Keycode.F6},
    {SDLK_F7, Keycode.F7},
    {SDLK_F8, Keycode.F8},
    {SDLK_F9, Keycode.F9},
    {SDLK_F10, Keycode.F10},
    {SDLK_F11, Keycode.F11},
    {SDLK_F12, Keycode.F12},
    {SDLK_F13, Keycode.F13},
    {SDLK_F14, Keycode.F14},
    {SDLK_F15, Keycode.F15},
    {SDLK_NUMLOCK, Keycode.NUMLOCK},
    {SDLK_CAPSLOCK, Keycode.CAPSLOCK},
    {SDLK_SCROLLOCK, Keycode.SCROLLOCK},
    {SDLK_RSHIFT, Keycode.RSHIFT},
    {SDLK_LSHIFT, Keycode.LSHIFT},
    {SDLK_RCTRL, Keycode.RCTRL},
    {SDLK_LCTRL, Keycode.LCTRL},
    {SDLK_RALT, Keycode.RALT},
    {SDLK_LALT, Keycode.LALT},
    {SDLK_RMETA, Keycode.RMETA},
    {SDLK_LMETA, Keycode.LMETA},
    {SDLK_LSUPER, Keycode.LSUPER},
    {SDLK_RSUPER, Keycode.RSUPER},
    {SDLK_MODE, Keycode.MODE},
    {SDLK_COMPOSE, Keycode.COMPOSE},
    {SDLK_HELP, Keycode.HELP},
    {SDLK_PRINT, Keycode.PRINT},
    {SDLK_SYSREQ, Keycode.SYSREQ},
    {SDLK_BREAK, Keycode.BREAK},
    {SDLK_MENU, Keycode.MENU},
    {SDLK_POWER, Keycode.POWER},
    {SDLK_EURO, Keycode.EURO},
    {SDLK_UNDO, Keycode.UNDO},

    //mouse button states
    //one must not overwrite existing or future SDLK_* constants
    //this is not particularly clean, but it works
    //the translation is useful, because we don't need to rely that the
    //Keycode.MOUSE_* constants have the same order like the SDL mouse buttons
    {g_sdl_mouse_button1 + 0, Keycode.MOUSE_LEFT},
    {g_sdl_mouse_button1 + 1, Keycode.MOUSE_MIDDLE},
    {g_sdl_mouse_button1 + 2, Keycode.MOUSE_RIGHT},
    {g_sdl_mouse_button1 + 3, Keycode.MOUSE_WHEELUP},
    {g_sdl_mouse_button1 + 4, Keycode.MOUSE_WHEELDOWN},
    {g_sdl_mouse_button1 + 5, Keycode.MOUSE_BUTTON6},
    {g_sdl_mouse_button1 + 6, Keycode.MOUSE_BUTTON7},
    {g_sdl_mouse_button1 + 7, Keycode.MOUSE_BUTTON8},
    {g_sdl_mouse_button1 + 8, Keycode.MOUSE_BUTTON9},
    {g_sdl_mouse_button1 + 9, Keycode.MOUSE_BUTTON10},
];

//hope SDL never uses negative values for its key constants
//at least this is more reliable than using SDLK_LAST
public static final const int g_sdl_mouse_button1 = -20;
